﻿[System.Serializable]
public enum GameScoreIncreaseType
{
    Miss,
    Best,
    Good,
    Bad,
}

[System.Serializable]
public class GameScore
{
    private int best;
    private int good;
    private int bad;
    private int miss;
    private int fullPress;
    private int combo;
    private int maxCombo;

    public int Best => best;
    public int Good => good;
    public int Bad => bad;
    public int Miss => miss;
    public int FullPress => fullPress;
    public int Combo => combo;
    public int MaxCombo => maxCombo;
    
    /// <summary>
    /// The value of process is between 0.0f ( include ) to 1.0f ( exclude )
    /// </summary>
    /// <param name="process"></param>
    public GameScoreIncreaseType IncreaseScore(float process)
    {
        GameScoreIncreaseType type;

        process %= 1.0f;

        if (process < 1.0f && process >= 0.8f)
        {
            best++;
            type = GameScoreIncreaseType.Best;
        }
        else if (process < 0.8f && process >= 0.6f)
        {
            good++;
            type = GameScoreIncreaseType.Good;
        }
        else if (process < 0.6f && process >= 0.4f)
        {
            bad++;
            type = GameScoreIncreaseType.Bad;
        }
        else
        {
            miss++;
            type = GameScoreIncreaseType.Miss;
        }

        switch(type)
        {
            case GameScoreIncreaseType.Miss:
                CorrectMaxCombo();
                combo = 0; break;
            default: combo++;break;
        }

        CorrectMaxCombo();
        fullPress++;
        return type;
    }

    public void AddMiss()
    {
        miss++;
        fullPress++;
        CorrectMaxCombo();
        combo = 0;
    }

    public bool IsFullCombo()
    {
        return (best + good) == fullPress;
    }

    private void CorrectMaxCombo()
    {
        if (combo > maxCombo)
            maxCombo = combo;
    }
}
